import 'package:json_annotation/json_annotation.dart';

import '../utils/http.dart';

part 'error_info.g.dart';

@JsonSerializable()
class ErrorInfo {
  static ErrorInfo unknownError = ErrorInfo(code: 9999, message: '未知异常');

  int code;
  String message;

  ErrorInfo({this.code, this.message});

  factory ErrorInfo.fromJson(Map<String, dynamic> json) =>
      _$ErrorInfoFromJson(json);
  Map<String, dynamic> toJson() => _$ErrorInfoToJson(this);

  factory ErrorInfo.fromHttpError(HttpError ex) {
    return ErrorInfo(
      code: ex.statusCode,
      message: ex.message,
    );
  }
}
